/**
 * Created with IntelliJ IDEA.
 * User: ajhin
 * Date: 8/5/14
 * Time: 5:07 PM
 * To change this template use File | Settings | File Templates.
 */
package societyGames.codeAlong.model
{
import societyGames.xmlFragment.XMLFragment;

public class EntryReplaceable extends XMLFragment
{
  public function get entry():String
  {
    if (_xml.hasOwnProperty("@entry"))
    {
      return _xml.@entry;
    }
    return null;
  }

  [Bindable]
  public function set entry(value:String):void
  {
    if (value)
    {
      _xml.@entry = value;
    }
    else
    {
      delete _xml["@entry"];
    }
  }

  public function get nodeText():String
  {
    var children:XMLList = _xml.children();
    if (children.length() == 0)
    {
      return "";
    }
    return _xml.children()[0].toString();
  }

  //TODO: Add a validator? Should be a single XML node.
  [Bindable]
  public function set nodeText(value:String):void
  {
    if (value != null)
    {
      _xml.setChildren(value);
    }
    else
    {
      _xml.setChildren(new XMLList());
    }
  }
}
}
